import axios from 'axios'

const api = axios.create({
  baseURL: '/api',
  timeout: 10000
})

// 请求拦截器
api.interceptors.request.use(
  (config) => {
    return config
  },
  (error) => {
    return Promise.reject(error)
  }
)

// 响应拦截器
api.interceptors.response.use(
  (response) => {
    return response.data
  },
  (error) => {
    return Promise.reject(error)
  }
)

// 式神相关API
export const shishenApi = {
  // 获取所有式神
  getAll: () => api.get('/shishen'),
  
  // 分页查询
  getPage: (pageNum, pageSize) => api.get(`/shishen/page?pageNum=${pageNum}&pageSize=${pageSize}`),
  
  // 条件查询
  search: (params) => api.get('/shishen/search', { params }),
  
  // 根据ID获取
  getById: (id) => api.get(`/shishen/${id}`),
  
  // 新增
  create: (data) => api.post('/shishen', data),
  
  // 更新
  update: (data) => api.put('/shishen', data),
  
  // 删除
  delete: (id) => api.delete(`/shishen/${id}`),
  
  // 批量删除
  batchDelete: (ids) => api.post('/shishen/batchDelete', ids)
}

export default api